package com.cjm.one.goods.admin.controller;


import com.cjm.one.common.result.Result;
import com.cjm.one.goods.service.GoodsUnitService;
import com.cjm.one.model.goods.entity.GoodsUnit;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Tag(name = "2商品单位")
@RequestMapping("/admin/goods/unit")
public class GoodsUnitController {
    @Resource
    private GoodsUnitService goodsUnitService;
    @GetMapping("/list")
    @Operation(summary = "商品单位列表")
    public Result<List<GoodsUnit>> list() {
        List<GoodsUnit> list = goodsUnitService.list();
        return Result.ok(list);
    }
    @PostMapping
    @Operation(summary = "添加商品单位")
    public Result<Boolean> add(@RequestBody  GoodsUnit goodsUnit) {
        log.info("添加商品单位:{}", goodsUnit);
        boolean save = goodsUnitService.save(goodsUnit);
        return Result.ok(save);
    }
    @DeleteMapping("/{id}")
    @Operation(summary = "删除商品单位")
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean flag = goodsUnitService.removeById(id);
        return Result.ok(flag);
    }
}
